<?php
declare (strict_types=1);

namespace app\job\command;

use app\api\model\App as AppModel;
use app\api\model\order\Order as OrderModel;
use app\common\library\storage\Driver as StorageDriver;
use Carbon\Carbon;
use Redis;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Cache;
use Workerman\Worker;
use Workerman\Lib\Timer;
use app\common\library\supply\Driver as SupplyDriver;

class Test extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('test')->setDescription('测试');
    }

    protected function execute(Input $input, Output $output)
    {

        dd(Cache::set("123123123", time(), 60));
        $cacheKey = "task_space_UserCoupon";
        if (!Cache::has($cacheKey)) {
            // 设置优惠券过期状态
            Cache::set($cacheKey, time(), 60);
        }


//        $detail = OrderModel::getUserOrderDetail(91, 8);
//        event('PaySuccess', $detail);
//        dd(1);


        $supplyDriver = new SupplyDriver([
            "default" => "Tao",
            "engine" => [
                "Tao" => []
            ]
        ]);
        $param = [
            "commodityId" => 100,
            "username" => 4,
            "outOrderId" => uniqid(),
            "notifyUrl" => 4,
        ];
        $supplyDriver->sendData($param);
        $justRecharge = $supplyDriver->justRecharge();
        dd($justRecharge);


        $token = $this->token("ozYTb6J54IuDEQWKqjfKJGnyFp0Q");
        // 记录缓存, 7天
        Cache::tag('cache')->set($token, 8, 86400 * 7);
//        hash_hmac("sha256", "appId=a1f1wgv3039vc75x@{$time}","f4f9d3761ee53020251386f01eaaf321")
//        dd($token);

    }

    private function token($openid)
    {
        $app_id = 10001;
        // 生成一个不会重复的随机字符串
        $guid = \getGuidV4();
        // 当前时间戳 (精确到毫秒)
        $timeStamp = microtime(true);
        // 自定义一个盐
        $salt = 'token_salt';
        return md5("{$app_id}_{$timeStamp}_{$openid}_{$guid}_{$salt}");
    }

}
